
package net.swa.index.web.action;

import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Required;
import net.swa.dewei.beans.entity.DingDan;
import net.swa.dewei.beans.entity.MenDian;
import net.swa.dewei.service.MenDianService;
import net.swa.util.JsonResult;

/**
 * MobiChargeAction
 * 
 * @author Administrator
 * 
 */
public class MobiChargeAction extends AbstractBaseIndexAction
{
    private static final long serialVersionUID = 7868090805552756795L;

    private final Logger log = Logger.getLogger(MobiChargeAction.class);

    /** 门店查询接口 */
    private MenDianService menDianService;

    /**没有持久化**/
    private DingDan model;

    private String json;

    private Long id;

    private Double lat;

    private Double lng;

    /** 微信id */
    private String wxid;

    /** 公众号id **/
    private String gzhId;

    /** 安全令牌 */
    private String token;

    /**
     * 1.跳转到移动设备浏览主页面
     * 入口
     * @return
     * @throws Exception
     */
    public String main() throws Exception
    {
        model = new DingDan();
        if (!StringUtils.isBlank(wxid))
        {
            // 将wxid 保存到session
            setSessionAttribute("wxid", wxid);
            addCookie("wxid", wxid);
            if (null != lat && null != lng)
            {
                model.setLat(lat);
                model.setLng(lng);
                //本身就是谷歌坐标系
                model.setBlat(lat);
                model.setBlng(lng);
            }
        }
        else
        {
            if (log.isDebugEnabled())
            {
                log.debug("没有获取wxid,访问附近手机充电站门店。。");
            }
            return "main";
        }
        // 获取车辆类型
        return "main";
    }

    /**
     * 2.根据传入的经纬度，取方圆指定范围的店面
     * 
     * @throws Exception
     */
    public String getMakers() throws Exception
    {
        if (null != lat && null != lng)
        {
            List<MenDian> list = menDianService.queryMobiChargeByLatLng(lat, lng, 20, true);
            JsonResult<MenDian> json = new JsonResult<MenDian>();
            json.setSuccess(true);
            json.setResult(list);
            outJson(json);
        }
        else
        {
            outError("经纬度获取失败");
        }
        return null;
    }

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    @Required
    @Resource
    public void setMenDianService(MenDianService menDianService)
    {
        this.menDianService = menDianService;
    }

    public Double getLat()
    {
        return lat;
    }

    public void setLat(Double lat)
    {
        this.lat = lat;
    }

    public Double getLng()
    {
        return lng;
    }

    public void setLng(Double lng)
    {
        this.lng = lng;
    }

    public String getWxid()
    {
        return wxid;
    }

    public void setWxid(String wxid)
    {
        this.wxid = wxid;
    }

    public String getGzhId()
    {
        return gzhId;
    }

    public void setGzhId(String gzhId)
    {
        this.gzhId = gzhId;
    }

    public String getToken()
    {
        return token;
    }

    public void setToken(String token)
    {
        this.token = token;
    }

    public String getJson()
    {
        return json;
    }

    public void setJson(String json)
    {
        this.json = json;
    }

    public DingDan getModel()
    {
        return model;
    }

    public void setModel(DingDan model)
    {
        this.model = model;
    }

}
